package com.example.nonggo.model;

import com.allen.library.RxHttpUtils;
import com.allen.library.interceptor.Transformer;
import com.example.nonggo.Constants;
import com.example.nonggo.api.BaseApi;
import com.example.nonggo.api.MDataObserver;
import com.example.nonggo.bean.ConditionRes;
import com.example.nonggo.bean.LoginRes;
import com.example.nonggo.contract.WeatherContract;
import com.tencent.mmkv.MMKV;

import org.json.JSONException;
import org.json.JSONObject;

import okhttp3.RequestBody;

public class WeatherModel extends BaseModel{


   public void getCondition(String province, String city, String county, WeatherContract.Presenter callback){
       RxHttpUtils.
               createApi(BaseApi.class).getCondition("Bearer "+token,getConditionBody(province,city,county))
               .compose(Transformer.switchSchedulers(null))
               .subscribe(new MDataObserver<ConditionRes>(){

                   @Override
                   protected void onSuccess(ConditionRes data) {
                       callback.getConditionSuccess(data);
                   }
               });
   }
    private RequestBody getConditionBody(String province,String city,String county) {
        JSONObject jb = new JSONObject();
        try {
            jb.put("province", province);
            jb.put("city", city);
            jb.put("county", county);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return getRequestBody(jb);
    }
}
